using System;
using System.Collections;
using System.Collections.Generic;
using TowerDefence_Study;
using UnityEngine;
using UnityEngine.UI;
using WuLibrary;


namespace  TowerDefence
{
    public class UI_Main : UILayer
    {
        private Text mTitleTex;

        private Button mStartBtn;

        private Text mBgText;

        private Text mSoundText;

        public override void OnEnter()
        {
          ColorDebugTools.Log("进入面板",LogColor.Blue);
        }

        public override void OnExit()
        {
            ColorDebugTools.Log("退出面板",LogColor.Blue);
        }

        public override void OnNodeLoad()
        {
            mTitleTex.text = "Tower Defence";
            mBgText.text = "BGM" + (AudioManager.IsBgOn ? "开" : "关");
            mSoundText.text = "Sound" + (AudioManager.IsSoundOn ? "开" : "关");

        }

       
      protected  override void OnNodeAsset(string name, GameObject obj)
        {
            switch (name)
            {
                case "TitleText":
                    mTitleTex =obj.GetComponent<Text>();
                    break;
                case "StartGameBtn":
                    mStartBtn=obj.GetComponent<Button>();
                    break;
                case "BgText":
                    mBgText=obj.GetComponent<Text>();
                    break;
                case "SoundTex":
                    mSoundText=obj.GetComponent<Text>();
                    break;
                    
            }
        }
        

        protected override void OnButtonClick(string name, GameObject obj)
        {
            switch (name)
            {
                case "StartGameBtn":
                    ColorDebugTools.Log("开始游戏", LogColor.Blue);
                    this.Close();
                    UIManager.EnterUI<UISelectLevel>();
                    break;
                case "BgBtn":
                    var isBgOn = !AudioManager.IsBgOn;
                    AudioManager.SetBgOn(isBgOn);
                    mBgText.text = "BGM" + (AudioManager.IsBgOn ? "开" : "关");
                    break;
                case "SoundBtn":
                    var isSoundOn = !AudioManager.IsSoundOn;
                    AudioManager.SetSoundOn(isSoundOn);
                    mSoundText.text = "Sound" + (AudioManager.IsSoundOn ? "开" : "关");
                    break;
            }
        }
    }

}
